package com.xw.xpermission;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.NonNull;

public class CustomXpDialog extends Dialog {

    private TextView messageText;
    private TextView negativeBtn;
    private TextView positiveBtn;
    private XPermisReasonListener xPermisReasonListener;
    private String message;

    public CustomXpDialog(@NonNull Context context) {
        this(context,0);
    }

    public CustomXpDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    public void setMessage(String message) {
        this.message = message;
        if (messageText != null) {
            messageText.setText(message);
        }
    }

    public void setxPermisReasonListener(XPermisReasonListener xPermisReasonListener) {
        this.xPermisReasonListener = xPermisReasonListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xp_dialog_default);

        messageText = findViewById(R.id.message_text);
        negativeBtn = findViewById(R.id.negative_btn);
        positiveBtn = findViewById(R.id.positive_btn);

        messageText.setText(message);
        negativeBtn.setOnClickListener(v -> {
            if (xPermisReasonListener != null) {
                xPermisReasonListener.onRefuse();
            }
            dismiss();
        });

        positiveBtn.setOnClickListener(v -> {
            if (xPermisReasonListener != null) {
                xPermisReasonListener.onSuccess();
            }
            dismiss();
        });
    }
}
